/*
 * Copyright 2013-2015 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jmax.starter;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

/**
 * 
 * @author max.zheng
 * @create 2015-10-17下午9:54:37
 * @since 1.0
 * @see
 */
public class StartMain {

	/**
	 * 
	 * @author max.zheng
	 * @create 2015-10-17下午9:54:38
	 * @modified by
	 * @param args
	 */
	public static void main(String[] args) {

		try {

			String lookAndFeel = UIManager.getSystemLookAndFeelClassName();

			UIManager.setLookAndFeel(lookAndFeel);

		} catch (Exception e) {
			e.printStackTrace();
		}
		new Hello();
	}

}

class Hello extends JPanel {
	/** 
     *  
     */
	private static final long serialVersionUID = 1L;
	static final int WIDTH = 300;
	static final int HEIGHT = 150;
	JFrame loginframe;

	// /按照网格组布局方式排列组件的方法
	// /x指控件位于第几列。
	// /y指控件位于第几行。
	// /w指控件需要占几列。
	// /h指控件需要占几行。
	public void add(Component c, GridBagConstraints constraints, int x, int y,
			int w, int h) {
		constraints.gridx = x;
		constraints.gridy = y;
		constraints.gridwidth = w;
		constraints.gridheight = h;
		add(c, constraints);
	} 
	// 此方法用来添加控件到容器中
		// /这是一个构造器方法
	// /loginframe是就是指这个界面的框架
	// / setDefaultCloseOperation这是一个使得窗口上面的关闭控件有效的类库方法
	// / lay是一个网格组布局管理器的对象。
	// / nameinput是用来输入用户名的文本域。
	// / passwordinput是用来输入密码的文本域。
	// / title是用来显示标题的标签。
	// / name是用来显示“姓名”的标签。
	// /password是用来显示“密码”的标签。
	// /ok是一个按钮，使进入系统。
	// /cancel是一个按钮，使退出界面和系统。
	// / ok.addActionListener是一个进入系统动作事件监听方法。
	// /cancel.addActionListener是一个退出系统和界面动作事件的监听方法。

	Hello() {
		loginframe = new JFrame("欢迎进入Java世界");
		loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout lay = new GridBagLayout();
		setLayout(lay);
		loginframe.add(this, BorderLayout.WEST);
		loginframe.setSize(WIDTH, HEIGHT);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		int x = (width - WIDTH) / 2;
		int y = (height - HEIGHT) / 2;
		loginframe.setLocation(x, y);
		JButton ok = new JButton("登录");
		JButton cancel = new JButton("放弃");
		JLabel title = new JLabel("欢迎进入Java世界");
		JLabel name = new JLabel("用户名");
		JLabel password = new JLabel("密 码");
		final JTextField nameinput = new JTextField(15);
		final JTextField passwordinput = new JTextField(15);
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.NONE;
		constraints.anchor = GridBagConstraints.EAST;
		constraints.weightx = 3;
		constraints.weighty = 4;
		add(title, constraints, 0, 0, 4, 1); // 使用网格组布局添加控件
		add(name, constraints, 0, 1, 1, 1);
		add(password, constraints, 0, 2, 1, 1);
		add(nameinput, constraints, 2, 1, 1, 1);
		add(passwordinput, constraints, 2, 2, 1, 1);
		add(ok, constraints, 0, 3, 1, 1);
		add(cancel, constraints, 2, 3, 1, 1);
		loginframe.setResizable(false);
		loginframe.setVisible(true);

	}
}
